-
Couldn't load subscription status.
- Fork 2k
fix(chroma): handle collection not found exception during initialization #4702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug in the Chroma vector store initialization where the collection existence check broke due to an upstream API error message change. The fix replaces fragile string-based error detection with robust HTTP 404 status code checking.
Key Changes:
- Replaced string matching on error messages with HTTP status code checking using
HttpClientErrorException.NotFound - Added proper exception handling with try-catch block to differentiate between "collection not found" (404) and genuine errors
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| collection = this.chromaApi.getCollection(this.tenantName, this.databaseName, this.collectionName); | ||
| } | ||
| catch (Exception ex) { | ||
| if (!(ex.getCause() instanceof HttpClientErrorException.NotFound)) { |
Copilot
AI
Oct 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exception handling logic checks ex.getCause() for HttpClientErrorException.NotFound, but if chromaApi.getCollection() directly throws HttpClientErrorException.NotFound (not wrapped), this check will fail and re-throw the exception incorrectly. Consider also checking if ex itself is an instance of HttpClientErrorException.NotFound before checking the cause: if (!(ex instanceof HttpClientErrorException.NotFound || ex.getCause() instanceof HttpClientErrorException.NotFound))
| if (!(ex.getCause() instanceof HttpClientErrorException.NotFound)) { | |
| if (!(ex instanceof HttpClientErrorException.NotFound || ex.getCause() instanceof HttpClientErrorException.NotFound)) { |
Add try-catch block to handle HttpClientErrorException.NotFound when getting collection during initialization. This prevents initialization failures when the collection doesn't exist yet. Signed-off-by: hanjie <[email protected]>
| collection = this.chromaApi.getCollection(this.tenantName, this.databaseName, this.collectionName); | ||
| } | ||
| catch (Exception ex) { | ||
| if (!(ex.getCause() instanceof HttpClientErrorException.NotFound)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this check be part of ChromaApi:233?
If I am not mistaken, the ChromaApi still contains the exception message check.
That exception message check will also still prevent ChromaApi#getCollection() from returning null, when a collection not exists, although returning null seems to be the expected behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I’ve looked into this further and realized the issue is in Spring AI’s own Chroma client implementation.
The error message check on line 233 currently uses:
String.format("Collection [%s] does not exists", collectionName)However, the actual response from the Chroma server is:
Collection [...] does not exist
Since the Chroma HTTP API returns "does not exist" ,As a result, the null-return path for missing collections is never triggered.
The fix is simply to update the expected message::
if (String.format("Collection [%s] does not exist", collectionName).equals(msg)) {
return null;
}I’m happy to submit a quick PR if that would be helpful!
Fix collection existence check broken by error message change in Chroma API.
The Chroma backend recently changed its error message from:
"Collection [...] does not exists"
to:
"Collection [...] does not exist"
This broke the string-based detection in
getCollection(), causing 404s to be treated as unexpected errors and preventing initialization.This PR replaces fragile string matching with reliable HTTP 404 status code checking via
HttpClientErrorException.NotFound.